import fetcher from "../apis/Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";
import {OffsetDateTime} from "@js-joda/core";

export interface QueryProcurementSuppliersRequest {
    name?: string
}

export function queryProcurementSuppliers(queryProcurementSuppliersRequest: QueryProcurementSuppliersRequest, pageable: Pageable) {
    return fetcher.get<Page<QueryProcurementSuppliersResponse>>("/procurementSuppliers", {...queryProcurementSuppliersRequest, ...pageable.toRequestParams()})
}

export interface QueryProcurementSuppliersResponse{
    id:number
    name:string
    amount:number
    lastOrderSubmittedDateTime: OffsetDateTime
}

export interface CreateProcurementSupplierRequest{
    name:string
}

export function createProcurementSupplier(createProcurementSupplierRequest:CreateProcurementSupplierRequest){
    return fetcher.post("procurementSuppliers",{},createProcurementSupplierRequest)
}

export function updateProcurementSupplier(id:number,createProcurementSupplierRequest:CreateProcurementSupplierRequest){
    return fetcher.put(`procurementSuppliers/${id}`,{},createProcurementSupplierRequest)
}

export function getAllProcurementSupplier(){
    return fetcher.get<Array<NumberIdAndName>>("procurementSuppliers")
}

export function getProcurementSupplierDetail(id:number){
    return fetcher.get<ProcurementSupplierDetail>(`procurementSuppliers/${id}`)
}

export interface ProcurementSupplierDetail{
    id:number
    name:string
    selectableBrands:Array<NumberIdAndName>
}